import instance from "@/utils/http";

// 获取轮播图接口
export const getSwiperApi = () => {
    return instance({
        url: `/api1/getCarousels.do`
    });
};

// 获取店铺列表
export const getShopsApi = () => {
    return instance({
        url: `/api1/getAllShops.do`
    });
};

// 获取店铺详情
export const getShopsDetailApi = (id) => {
    return instance({
        url: `/api1/getShopById.do?shop_id=${id}`
    });
};
// 获取店铺菜单
export const getFoodsApi = (id) => {
    return instance({
        url: `/api1/getFoodByShop.do?shop_id=${id}`
    });
};

// 获取店铺菜单详情
export const getFoodsDetailApi = (id) => {
    return instance({
        url: `/api1/getFoodById.do?food_id=${id}`
    });
};

//添加购物车
export const insertCartApi = data => {
    return instance({
        url: `/api1/addCart.do?user_id=${data.userId}&food_id=${data.foodId}&num=1`
    });
};
//获取购物车信息
export const getCartApi = id => {
    return instance({
        url: `/api1/getMyCartByUser.do?user_id=${id}`
    });
};
//删除购物车中商品
export const deleteCartApi = id => {
    return instance({
        url: `/api1/deleteCartItem.do?item_id=${id}`
    });
};
// 直接购买接口
export const insertOrderApi = data => {
    return instance({
        url: `/api1/insertOrder.do?user_id=${data.userId}&food_id=${data.foodId}&num=${data.num}&sum=${data.sum}&suggesttime=${data.suggesttime}&address_id=7`
    });
};

// 注册用户
export const RegisterApi = data => {
    return instance({
        url: `/api1/userRegister.do?username=${data.username}&userpass=${data.userpass}&mobilenum=${data.mobilenum}&address=${data.address}&comment=${data.comment}`
    });
};

// 用户登录
export const LoginApi = data => {
    return instance({
        url: `/api1/userLogin.do?username=${data.username}&userpass=${data.userpass}`
    });
};
// 获取店铺菜单评论
export const getFoodsCommApi = (id) => {
    return instance({
        url: `/api1/getAllCommentsByFood.do?food_id=${id}`
    });
};
// 购物车中选择下单
export const getItemsApi = id => {
    return instance({
        url: `/api1/getItemsFromCart.do?items=${id}`
    });
};
// 批量购买
export const insertOrder2Api = data => {
    return instance({
        url: `/api1/insertOrder2.do?user_id=${data.userId}&address_id=7&sum=${data.sum}&suggesttime=${data.suggesttime}&items=${data.items}`
    });
};
// 获取用户数据
export const getUserApi = (id) => {
    return instance({
        url: `/api1/getUserById.do?user_id=${id}`
    });
};
// 获取订单数据
export const getAllOrdersByUserApi = (id) => {
    return instance({
        url: `/api1/getAllOrdersByUser.do?user_id=${id}`
    });
};
// 添加评论
export const insertCommentApi = (data) => {
    return instance({
        url: `/api1/insertComment.do?item_id=${data.itemId}&content=${data.content}`
    });
};
// 获取评论数据
export const getCommentApi = (id) => {
    return instance({
        url: `/api1/getAllCommentsByUser.do?user_id=${id}`
    });
};
// 修改评论
export const updateCommentApi = (data) => {
    return instance({
        url: `/api1/updateComment.do?item_id=${data.itemId}&content=${data.content}`
    });
};
// 删除评论
export const deleteCommentApi = (id) => {
    return instance({
        url: `/api1/deleteComment.do?item_id=${id}`
    });
};
// 收藏信息
export const getCollectionApi = (data) => {
    return instance({
        url: `/api1/getAllUserCollection.do?user_id=${data.userId}&flag=${data.flag}`
    });
};
// 收藏店铺数据
export const userCollectShopApi = (data) => {
    return instance({
        url: `/api1/userCollectShop.do?user_id=${data.userId}&shop_id=${data.shopId}`
    });
};
// 收藏商品数据
export const userCollectFoodApi = (data) => {
    return instance({
        url: `/api1/userCollectFood.do?user_id=${data.userId}&food_id=${data.foodId}`
    });
};
// 是否收藏接口
export const isCollectedApi = (data) => {
    return instance({
        url: `/api1/isCollected.do?user_id=${data.userId}&shop_food_id=${data.id}&flag=${data.flag}`
    });
};
// 获取搜索信息
export const getFoodBySearchApi = (data) => {
    return instance({
        url: `/api1/getFoodBySearch.do?search=${data}`
    });
};
// 修改用户信息
export const updateUserByIdApi = (data) => {
    return instance({
        url: `/api1/updateUserById.do?user_id=${data.userId}&username=${data.username}&userpass=${data.userpass}&mobilenum=${data.mobilenum}&address=${data.address}`
    });
};
